package com.seari.tunnel.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class TunnelOverviewController {
	private final String GCGK_PAGE = "/gcgk";
	private final String JSDW_PAGE = "/jsdw";
	private final String GLDW_PAGE = "/gldw";
	private final String SJDW_PAGE = "/sjdw";
	private final String JLDW_PAGE = "/jldw";
	private final String SGDW1B_PAGE = "/sgdw1b";
	private final String SGDW2B_PAGE = "/sgdw2b";
	private final String SGDW3B_PAGE = "/sgdw3b";
	private final String ZCFG_PAGE = "/zcfg";
	
	@RequestMapping(value="/gcgk")
	public ModelAndView gcgk(){
		
		return new ModelAndView(GCGK_PAGE);
	}
	
	@RequestMapping(value="/jsdw")
	public ModelAndView jsdw(){
		
		return new ModelAndView(JSDW_PAGE);
	}
	
	@RequestMapping(value="/gldw")
	public ModelAndView gldw(){
		
		return new ModelAndView(GLDW_PAGE);
	}
	
	@RequestMapping(value="/sjdw")
	public ModelAndView sjdw(){
		
		return new ModelAndView(SJDW_PAGE);
	}
	
	@RequestMapping(value="/jldw")
	public ModelAndView jldw(){
		
		return new ModelAndView(JLDW_PAGE);
	}
	
	@RequestMapping(value="/sgdw1b")
	public ModelAndView sgdw1b(){
		
		return new ModelAndView(SGDW1B_PAGE);
	}
	
	@RequestMapping(value="/sgdw2b")
	public ModelAndView sgdw2b(){
		
		return new ModelAndView(SGDW2B_PAGE);
	}
	
	@RequestMapping(value="/sgdw3b")
	public ModelAndView sgdw3b(){
		
		return new ModelAndView(SGDW3B_PAGE);
	}
	
	@RequestMapping(value="/zcfg")
	public ModelAndView zcfg(){
		
		return new ModelAndView(ZCFG_PAGE);
	}
	
	@RequestMapping(value="/downloadZCFG1")
	public void downloadZCFG1(HttpServletRequest req, HttpServletResponse res){
		InputStream is = null;
		OutputStream os = null;
		try {
			res.reset();
			String fileName = "关于开展2016年中央财政支持地下综合管廊试点工作的通知.pdf";
			 if(req.getHeader("User-Agent").toLowerCase().indexOf("firefox")>0){
	                fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");//firefox浏览器
	            }else if (req.getHeader("User-Agent").toUpperCase().indexOf("MSIE")>0){
	                fileName = URLEncoder.encode(fileName, "UTF-8");//IE浏览器
	            }else{
	                fileName = URLEncoder.encode(fileName, "UTF-8");
	            }
		res.setCharacterEncoding("utf-8");
		res.setContentType("application/pdf");
		res.setHeader("Content-Disposition", "attachment;fileName=\"" + fileName + "\"");

            String path = Thread.currentThread().getContextClassLoader()
                    .getResource("").getPath()
                    + "download";//这个tunneled目录为啥建立在classes下的
            is = new FileInputStream(new File(path
                    + File.separator + "关于开展2016年中央财政支持地下综合管廊试点工作的通知.pdf"));
 
            os = res.getOutputStream();
            byte[] mybyte = new byte[8192];
            int len = 0;
            while ((len = is.read(mybyte)) != -1) {
                os.write(mybyte, 0, len);
            }

            os.flush();
             // 这里主要关闭。
            os.close();
            is.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	@RequestMapping(value="/downloadZCFG2")
	public void downloadZCFG2(HttpServletRequest req, HttpServletResponse res){
		InputStream is = null;
		OutputStream os = null;
		try {
			res.reset();
			String fileName = "国务院办公厅关于推进城市地下综合管廊建设的指导意见.pdf";
			 if(req.getHeader("User-Agent").toLowerCase().indexOf("firefox")>0){
	                fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");//firefox浏览器
	            }else if (req.getHeader("User-Agent").toUpperCase().indexOf("MSIE")>0){
	                fileName = URLEncoder.encode(fileName, "UTF-8");//IE浏览器
	            }else{
	                fileName = URLEncoder.encode(fileName, "UTF-8");
	            }
		res.setCharacterEncoding("utf-8");
		res.setContentType("application/pdf");
		res.setHeader("Content-Disposition", "attachment;fileName=\"" + fileName + "\"");

            String path = Thread.currentThread().getContextClassLoader()
                    .getResource("").getPath()
                    + "download";//这个tunneled目录为啥建立在classes下的
            is = new FileInputStream(new File(path
                    + File.separator + "国务院办公厅关于推进城市地下综合管廊建设的指导意见.pdf"));
 
            os = res.getOutputStream();
            byte[] mybyte = new byte[8192];
            int len = 0;
            while ((len = is.read(mybyte)) != -1) {
                os.write(mybyte, 0, len);
            }

            os.flush();
             // 这里主要关闭。
            os.close();
            is.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	@RequestMapping(value="/downloadZCFG3")
	public void downloadZCFG3(HttpServletRequest req, HttpServletResponse res){
		InputStream is = null;
		OutputStream os = null;
		try {
			res.reset();
			String fileName = "关于印发《城市管网专项资金管理暂行办法》的通知.pdf";
			 if(req.getHeader("User-Agent").toLowerCase().indexOf("firefox")>0){
	                fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");//firefox浏览器
	            }else if (req.getHeader("User-Agent").toUpperCase().indexOf("MSIE")>0){
	                fileName = URLEncoder.encode(fileName, "UTF-8");//IE浏览器
	            }else{
	                fileName = URLEncoder.encode(fileName, "UTF-8");
	            }
		res.setCharacterEncoding("utf-8");
		res.setContentType("application/pdf");
		res.setHeader("Content-Disposition", "attachment;fileName=\"" + fileName + "\"");

            String path = Thread.currentThread().getContextClassLoader()
                    .getResource("").getPath()
                    + "download";//这个tunneled目录为啥建立在classes下的
            is = new FileInputStream(new File(path
                    + File.separator + "关于印发《城市管网专项资金管理暂行办法》的通知.pdf"));
 
            os = res.getOutputStream();
            byte[] mybyte = new byte[8192];
            int len = 0;
            while ((len = is.read(mybyte)) != -1) {
                os.write(mybyte, 0, len);
            }

            os.flush();
             // 这里主要关闭。
            os.close();
            is.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	@RequestMapping(value="/downloadZCFG4")
	public void downloadZCFG4(HttpServletRequest req, HttpServletResponse res){
		InputStream is = null;
		OutputStream os = null;
		try {
			res.reset();
			String fileName = "住房城乡建设部关于印发《城市地下综合管廊工程规划编制指引》的通知.pdf";
			 if(req.getHeader("User-Agent").toLowerCase().indexOf("firefox")>0){
	                fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");//firefox浏览器
	            }else if (req.getHeader("User-Agent").toUpperCase().indexOf("MSIE")>0){
	                fileName = URLEncoder.encode(fileName, "UTF-8");//IE浏览器
	            }else{
	                fileName = URLEncoder.encode(fileName, "UTF-8");
	            }
		res.setCharacterEncoding("utf-8");
		res.setContentType("application/pdf");
		res.setHeader("Content-Disposition", "attachment;fileName=\"" + fileName + "\"");

            String path = Thread.currentThread().getContextClassLoader()
                    .getResource("").getPath()
                    + "download";//这个tunneled目录为啥建立在classes下的
            is = new FileInputStream(new File(path
                    + File.separator + "住房城乡建设部关于印发《城市地下综合管廊工程规划编制指引》的通知.pdf"));
 
            os = res.getOutputStream();
            byte[] mybyte = new byte[8192];
            int len = 0;
            while ((len = is.read(mybyte)) != -1) {
                os.write(mybyte, 0, len);
            }

            os.flush();
             // 这里主要关闭。
            os.close();
            is.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	@RequestMapping(value="/downloadZCFG5")
	public void downloadZCFG5(HttpServletRequest req, HttpServletResponse res){
		InputStream is = null;
		OutputStream os = null;
		try {
			res.reset();
			String fileName = "关于《印发城市地下综合管廊建设专项债券发行指引》的通知.pdf";
			 if(req.getHeader("User-Agent").toLowerCase().indexOf("firefox")>0){
	                fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");//firefox浏览器
	            }else if (req.getHeader("User-Agent").toUpperCase().indexOf("MSIE")>0){
	                fileName = URLEncoder.encode(fileName, "UTF-8");//IE浏览器
	            }else{
	                fileName = URLEncoder.encode(fileName, "UTF-8");
	            }
		res.setCharacterEncoding("utf-8");
		res.setContentType("application/pdf");
		res.setHeader("Content-Disposition", "attachment;fileName=\"" + fileName + "\"");

            String path = Thread.currentThread().getContextClassLoader()
                    .getResource("").getPath()
                    + "download";//这个tunneled目录为啥建立在classes下的
            is = new FileInputStream(new File(path
                    + File.separator + "关于《印发城市地下综合管廊建设专项债券发行指引》的通知.pdf"));
 
            os = res.getOutputStream();
            byte[] mybyte = new byte[8192];
            int len = 0;
            while ((len = is.read(mybyte)) != -1) {
                os.write(mybyte, 0, len);
            }

            os.flush();
             // 这里主要关闭。
            os.close();
            is.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	@RequestMapping(value="/downloadZCFG6")
	public void downloadZCFG6(HttpServletRequest req, HttpServletResponse res){
		InputStream is = null;
		OutputStream os = null;
		try {
			res.reset();
			String fileName = "国务院办公厅关于加强城市地下管线建设管理的指导意见.pdf";
			 if(req.getHeader("User-Agent").toLowerCase().indexOf("firefox")>0){
	                fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");//firefox浏览器
	            }else if (req.getHeader("User-Agent").toUpperCase().indexOf("MSIE")>0){
	                fileName = URLEncoder.encode(fileName, "UTF-8");//IE浏览器
	            }else{
	                fileName = URLEncoder.encode(fileName, "UTF-8");
	            }
		res.setCharacterEncoding("utf-8");
		res.setContentType("application/pdf");
		res.setHeader("Content-Disposition", "attachment;fileName=\"" + fileName + "\"");

            String path = Thread.currentThread().getContextClassLoader()
                    .getResource("").getPath()
                    + "download";//这个tunneled目录为啥建立在classes下的
            is = new FileInputStream(new File(path
                    + File.separator + "国务院办公厅关于加强城市地下管线建设管理的指导意见.pdf"));
 
            os = res.getOutputStream();
            byte[] mybyte = new byte[8192];
            int len = 0;
            while ((len = is.read(mybyte)) != -1) {
                os.write(mybyte, 0, len);
            }

            os.flush();
             // 这里主要关闭。
            os.close();
            is.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	@RequestMapping(value="/downloadZCFG7")
	public void downloadZCFG7(HttpServletRequest req, HttpServletResponse res){
		InputStream is = null;
		OutputStream os = null;
		try {
			res.reset();
			String fileName = "国务院关于加强城市基础设施建设的意见.pdf";
			 if(req.getHeader("User-Agent").toLowerCase().indexOf("firefox")>0){
	                fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");//firefox浏览器
	            }else if (req.getHeader("User-Agent").toUpperCase().indexOf("MSIE")>0){
	                fileName = URLEncoder.encode(fileName, "UTF-8");//IE浏览器
	            }else{
	                fileName = URLEncoder.encode(fileName, "UTF-8");
	            }
		res.setCharacterEncoding("utf-8");
		res.setContentType("application/pdf");
		res.setHeader("Content-Disposition", "attachment;fileName=\"" + fileName + "\"");

            String path = Thread.currentThread().getContextClassLoader()
                    .getResource("").getPath()
                    + "download";//这个tunneled目录为啥建立在classes下的
            is = new FileInputStream(new File(path
                    + File.separator + "国务院关于加强城市基础设施建设的意见.pdf"));
 
            os = res.getOutputStream();
            byte[] mybyte = new byte[8192];
            int len = 0;
            while ((len = is.read(mybyte)) != -1) {
                os.write(mybyte, 0, len);
            }

            os.flush();
             // 这里主要关闭。
            os.close();
            is.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
}
